package com.zoo.boot.bean;

import com.zoo.boot.model.LMenu;
import com.zoo.boot.model.LRole;
import com.zoo.boot.model.LUser;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;

import java.util.Collection;
import java.util.List;

/**
 * 封装了Security认证授权所需的信息
 * @Author: WangB
 * @Date: 2021/6/25
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
public class JwtUser implements UserDetails {


    //用户信息
    private LUser user;

    //角色信息
    private LRole role;

    //菜单信息
    private List<LMenu> lMenus;

    //权限信息
    private List<GrantedAuthority> authorities;


    public  JwtUser(LUser user,List<GrantedAuthority> authorities){
        this.user = user;
        this.authorities =authorities;
    }


    @Override
    public Collection<? extends GrantedAuthority> getAuthorities() {
        return authorities;
    }

    @Override
    public String getPassword() {
        return user.getPassword();
    }

    @Override
    public String getUsername() {
        return user.getUserName();
    }

    @Override
    public boolean isAccountNonExpired() {
        return true;
    }

    @Override
    public boolean isAccountNonLocked() {
        return true;
    }

    @Override
    public boolean isCredentialsNonExpired() {
        return true;
    }

    @Override
    public boolean isEnabled() {
        return true;
    }
}
